import axios from 'axios'
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';
axios.defaults.baseURL = 'http://10.20.12.115:8080/';
axios.defaults.timeout = 30000;

axios.interceptors.request.use(config => {
    config.headers.token = window.sessionStorage.getItem('token');
    return config;
});


axios.interceptors.response.use(res =>{
    const code = res.data.code || 200;
    if(code === 500){
        return Promise.resolve(res.data);
    }else if(code === 401){
        return Promise.reject(new Error(res.data.data));
    }else if(code === 200){
        return res.data;
    }
},error => {
    console.log('err' + error);
    return Promise.reject(error);
});

export default axios
